#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int T;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    scanf("%d",&T);
    while(T--){
        int n,a[N],ans=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(a[j]==a[i]) ans+=a[i];
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
